package cn.util;

import org.apache.commons.math3.distribution.CauchyDistribution;
import org.apache.commons.math3.distribution.RealDistribution;

import java.util.Random;

public class RealDistributionHelper {
    public static final RealDistribution REAL_DISTRIBUTION = new CauchyDistribution();

    private RealDistributionHelper() {
        throw new AssertionError("this instance is not suit for you");
    }

    private static final Random random = new Random();

    /**
     * @param min 域最小值
     * @param max 域最大值
     * @return 柯西分布的概率的求反
     */
    public static double inverseCumulativeProbability(double min, double max) {
        if (max < min) {
            throw new IllegalArgumentException("min can not great than max!");
        }

        double probability = random.nextDouble();
        // TODO: 此处求的是柯西概率的求反, 无意义，但无更优想法
        return REAL_DISTRIBUTION.inverseCumulativeProbability(probability);
    }

}
